/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.portlet.description.impl;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.genia.toolbox.basics.i18n.EnumDescriptable;
import com.genia.toolbox.basics.i18n.I18nMessage;
import com.genia.toolbox.basics.i18n.I18nMessageFactory;
import com.genia.toolbox.constants.client.i18n.Messages;

/**
 * implementation of the <code>VariableDescription</code> for a variable of
 * type <code>Long</code>.
 */
public class EnumerationVariableDescription
    extends AbstractVariableDescription
{

  /**
   * the enumeration that are acceptable values for this parameter.
   */
  private List<Enum<?>> enumConstants = Arrays.asList();



  /**
   * Because this variable must be selected in a list, there is no verification
   * made.
   * 
   * @param value
   *          the value to check
   * @return <code>null</code>.
   * @see com.genia.toolbox.web.portlet.description.VariableDescription#accept(java.lang.String)
   */
  public I18nMessage accept(final String value)
  {
    return null;
  }



  /**
   * return the list of acceptable values.
   * 
   * @return the list of acceptable values
   * @see com.genia.toolbox.web.portlet.description.VariableDescription#getValues()
   */
  public Map<I18nMessage, String> getValues()
  {
    Map<I18nMessage, String> values = new LinkedHashMap<I18nMessage, String>();
    for (Enum<?> enumeration : enumConstants) {
      if (enumeration instanceof EnumDescriptable) {
        values.put(((EnumDescriptable) enumeration).getDescription(), enumeration.name());
      }
      else {
        values.put(I18nMessageFactory.getIl8nMessage(Messages.SHOW_PARAMETER_KEY, enumeration.name()), enumeration.name());
      }
    }
    return values;
  }



  /**
   * setter for the enumClass property.
   * 
   * @param enumClass
   *          the enumClass to set
   */
  public void setEnumClass(Class<Enum<?>> enumClass)
  {
    this.enumConstants = Arrays.asList(enumClass.getEnumConstants());
  }

}
